import 'package:flutter_fronter_service/generated/json/base/json_convert_content.dart';
import 'package:flutter_fronter_service/model/sku_entity.dart';
import 'package:flutter_fronter_service/model/properties_entity.dart';


SkuEntity $SkuEntityFromJson(Map<String, dynamic> json) {
  final SkuEntity skuEntity = SkuEntity();
  final int? id = jsonConvert.convert<int>(json['id']);
  if (id != null) {
    skuEntity.id = id;
  }
  final int? itemStock = jsonConvert.convert<int>(json['itemStock']);
  if (itemStock != null) {
    skuEntity.itemStock = itemStock;
  }
  final double? goodsPrice = jsonConvert.convert<double>(json['goodsPrice']);
  if (goodsPrice != null) {
    skuEntity.goodsPrice = goodsPrice;
  }
  final String? goodsName = jsonConvert.convert<String>(json['goodsName']);
  if (goodsName != null) {
    skuEntity.goodsName = goodsName;
  }
  final String? itemImg = jsonConvert.convert<String>(json['itemImg']);
  if (itemImg != null) {
    skuEntity.itemImg = itemImg;
  }
  final List<PropertiesEntity>? itemSpec = (json['itemSpec'] as List<dynamic>?)
      ?.map(
          (e) => jsonConvert.convert<PropertiesEntity>(e) as PropertiesEntity)
      .toList();
  if (itemSpec != null) {
    skuEntity.itemSpec = itemSpec;
  }
  return skuEntity;
}

Map<String, dynamic> $SkuEntityToJson(SkuEntity entity) {
  final Map<String, dynamic> data = <String, dynamic>{};
  data['id'] = entity.id;
  data['itemStock'] = entity.itemStock;
  data['goodsPrice'] = entity.goodsPrice;
  data['goodsName'] = entity.goodsName;
  data['itemImg'] = entity.itemImg;
  data['itemSpec'] = entity.itemSpec.map((v) => v.toJson()).toList();
  return data;
}

extension SkuEntityExtension on SkuEntity {
  SkuEntity copyWith({
    int? id,
    int? itemStock,
    double? goodsPrice,
    String? goodsName,
    String? itemImg,
    List<PropertiesEntity>? itemSpec,
  }) {
    return SkuEntity()
      ..id = id ?? this.id
      ..itemStock = itemStock ?? this.itemStock
      ..goodsPrice = goodsPrice ?? this.goodsPrice
      ..goodsName = goodsName ?? this.goodsName
      ..itemImg = itemImg ?? this.itemImg
      ..itemSpec = itemSpec ?? this.itemSpec;
  }
}